/* 
 * 定义itfreer.arcgis.book模块
 */
(function(window, angular, undefined){
	/* 
	 * 定义itfreer.arcgis.book模块
	 */
	var itfreerArcgisBook = angular.module('itfreer.arcgis.book', 
		['itfreer.form.core',
		'itfreer.arcgis.core']);

	/**
	 * 定义核心模块依赖注入器，定义地图的基础用法
	 */
	itfreerArcgisBook.factory('$itfreer_arcgis_book',
		function($rootScope, $gisObject, $formObject, $itfreer_core, 
			$itfreer_arcgis_core, $itfreer_form_core) {
			$itfreer_arcgis_book = {

				/**
				 * 加载数据
				 */
				initBookData : function(formName, tableName, keyField, randomFields, orderObject, formValue, queryValue, bpmKey, pageSize){
					$itfreer_form_core.initAndLoadData(formName, tableName, keyField, randomFields, orderObject, formValue, queryValue, bpmKey, pageSize);
				},

				/**
				 * 保存数据
				 */
				saveBook : function(formName){
					var row = $formObject[formName].editRow;
					var extent = $gisObject.map.extent;
					row["S_BOOKEXTENT"] = extent.xmin + "," + extent.ymin + "," 
						+ extent.xmax + "," + extent.ymax;

					var date = new Date();
					var y = date.getFullYear();
					var m = date.getMonth() + 1;
					var d = date.getDate();

					row["D_ADDTIME"] = y + '-' + m + '-' + d;
					row["USERID"] = $formObject.user.userid;
					$itfreer_form_core.save(formName);
				},

				/**
				 * 删除数据
				 */
				delBook : function(formName, row){
					$itfreer_form_core.delEntity(formName, row);
				},

				/**
				 * 绽放到
				 */
				extentTo : function(row){
					var extentString = row["S_BOOKEXTENT"];
					var wkid = 0;
					if($gisObject.mapisdlwkid){
						wkid = $gisObject.dlwkid;
					}else{
						wkid = $gisObject.tywkid;
					}
					var extent = $itfreer_arcgis_core.getExtentByString(extentString, wkid);
					$gisObject.map.setExtent(extent);
				}
			};
			for(f in $itfreer_arcgis_book){
				$rootScope[f] = $itfreer_arcgis_book[f];
			}
			return $itfreer_arcgis_book;
		}
	);

	/* 
	 * 加载服务器
	 */
	itfreerArcgisBook.run(function($rootScope, $itfreer_arcgis_book) {
	  	
	});
}(window, angular));